package nix.ssm.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class CustomExceptionResoler implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {

		// handler 发生异常的地方，包+类+方法（形参）
		// public java.lang.String nix.ssm.controller.ItemController.itemList(org.springframework.ui.Model)
		// 记录日志，Log4j
		
		ModelAndView mav = new ModelAndView();
		if (ex instanceof MyException) {
			MyException me = (MyException)ex;
			mav.addObject("error", me.getMsg());
		} else {
			mav.addObject("error", "未知异常");
		}	
		mav.setViewName("error");
		return mav;
	}

}
